package cn.bellychang.leetcode.question206;

/**
 * @author ChangLiang
 * @date 2021/1/26
 */
public class Solution2 {

    public ListNode reverseList(ListNode head) {
        ListNode prev = null;
        ListNode curr = head;

        // 循环不变量
        while(curr!=null){
            // 保留下一个curr位置
            ListNode next = curr.next;

            // 更改指向
            curr.next = prev;

            // 两个指针向前进
            prev = curr;
            curr = next;
        }
        return prev;
    }
}
